/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admingui;

import java.util.ArrayList;

/**
 *
 * @author galen
 */
public class AdminCommands {
    
    private ArrayList<String> XMLList;
    private ArrayList<Item> itemsList;
    private AdminXML admXML;
    
    
    public void updateQuantity(ArrayList<Item> items, ArrayList<Item> itemsCopy){
        String itemStr;
        
        XMLList = new ArrayList<String>();
        
        for(int i = 0; i < items.size(); i++){
     
            if (!items.get(i).getQuantity().equals(itemsCopy.get(i).getQuantity())){
                
                itemStr = admXML.removeToXML(items.get(i).getID(), items.get(i).getQuantity());
                XMLList.add(itemStr);
            }
        }
        for(int i = 0; i < XMLList.size(); i++){
            removeItem(XMLList.get(i));
            System.out.println(XMLList.get(i));
            
        }
    }
    
    public ArrayList getItems(){
        String itemXML;
        admXML = new AdminXML();
        itemXML = getAllItems();
        itemsList = admXML.createItemFromXML(itemXML);
        
        return itemsList;
    }
    
    public void addItem(String id, String name, String price, String quantity){
        String addItemXML;
        addItemXML = admXML.addItemToXML(id, name, price, quantity);
        
        addItem(addItemXML);
    }

    public void updateMonthAdmin(){
        updateMonth();
    }

    // TODO: Add to the GUI
    public String adminGetMonth(){
        String monthXML;
        String month = "";
        monthXML = getMonth();
        month = admXML.getMonthFromXML(monthXML);
        
        return month;
    }
    
    private static String getAllItems() {
        admingui.WarehouseService service = new admingui.WarehouseService();
        admingui.Warehouse port = service.getWarehousePort();
        return port.getAllItems();
    }

    private static String removeItem(java.lang.String removeItemXML) {
        admingui.WarehouseService service = new admingui.WarehouseService();
        admingui.Warehouse port = service.getWarehousePort();
        return port.removeItem(removeItemXML);
    }

    private static String getMonth() {
        admingui.WarehouseService service = new admingui.WarehouseService();
        admingui.Warehouse port = service.getWarehousePort();
        return port.getMonth();
    }

    private static String updateMonth() {
        admingui.WarehouseService service = new admingui.WarehouseService();
        admingui.Warehouse port = service.getWarehousePort();
        return port.updateMonth();
    }

    private static String addItem(java.lang.String addItemXML) {
        admingui.WarehouseService service = new admingui.WarehouseService();
        admingui.Warehouse port = service.getWarehousePort();
        return port.addItem(addItemXML);
    }
}
